package db;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import model.*;

/**
 *
 * @author Morten
 *
 * Furniture(String name, String discription, int value, String materiale,
 * String dimension) Jewelry(String name, String discription, int value, String
 * metal, String gem, String stamp) Painting(String name, String discription,
 * int value, String painter, int year, String artstyle, String size)
 * Wine(String name, String discription, int value, String manufacture, String
 * country, int year, String grapes, double percentage, String bottleSize, int
 * amount)
 */
public class LoadAll {

    private ArrayList<Auction> pro;
    private ArrayList<User> use;
    private ArrayList<Bid> bid;
    private static LoadAll instance;
    DateFormat d = new SimpleDateFormat("dd/mm/yy HH:mm:ss");

    public LoadAll() {
	pro=new ArrayList<>();
	use=new ArrayList<>();
	bid=new ArrayList<>();
	reload();
	loadUser();
	loadBid();
    }
    
    public static LoadAll getInstance(){
	if(instance==null){
	    instance=new LoadAll();
	}
	return instance;
    }

    public ArrayList<Auction> getProducts() {
	return pro;
    }

    public ArrayList<User> getUsers() {
	return use;
    }
    
    public ArrayList<Bid> getBidList(Auction auction){
	ArrayList<Bid> res=new ArrayList<>();
	for(Bid b : bid){
	    if(b.getAuction()==auction){
		res.add(b);
	    }
	}
	Collections.reverse(res);
	return res;
    }

    public void addBid(Auction a,User u, int b) {
	bid.add(new Bid(a,u,b));
    }

    
    private void reload() {
	pro.clear();
	pro.add(new Auction(2500, d.format(new Date(1392465600)), "Someone1", new Furniture("Sofa", "Sort to personers lædersofa", 5500, "Læder,Træ", "220x80x60")));
	pro.add(new Auction(500,  d.format(new Date(1392465600)), "Someone2", new Furniture("Bord", "Fire ben", 2000, "Træ", "160x80x80")));
	pro.add(new Auction(5000, d.format(new Date(1392465600)), "Someone3", new Furniture("Stol", "Designer stol", 15000, "Jern", "120x50x50")));
	pro.add(new Auction(200,  d.format(new Date(1392465600)), "Someone4", new Jewelry("Halskæde", "Bleh..", 800, "Sølv", "Ingen", "846WE")));
	pro.add(new Auction(3500, d.format(new Date(1392465600)), "Someone5", new Jewelry("Ring", "Bleh bleh..", 8000, "Guld", "Diamant", "SG4658")));
	pro.add(new Auction(8500, d.format(new Date(1392465600)), "Someone6", new Jewelry("Diadem", "Bleh2..", 10500, "Sølv", "Ingen", "GWE846")));
	pro.add(new Auction(5500, d.format(new Date(1392465600)), "Someone7", new Painting("Maleri", "Stor hest", 12000, "Svend Poulsen", 1978, "Fingermaling", "120x100")));
	pro.add(new Auction(6500, d.format(new Date(1392465600)), "Someone8", new Painting("Maleri2", "Lille hest", 20000, "Erik Thomsen", 1958, "Maling", "1200x1000")));
	pro.add(new Auction(3500, d.format(new Date(1392465600)), "Someone9", new Painting("Maleri3", "Mellem hest", 15000, "Carl Pedersen", 1980, "Acryl", "220x200")));
	pro.add(new Auction(1500, d.format(new Date(1392465600)), "Someone10", new Wine("Vin", "Rødvin", 4500, "Le Pas", "Frankrig", 1955, "Gode", 5.75, "750 cl", 1)));
	pro.add(new Auction(1000, d.format(new Date(1392465600)), "Someone11", new Wine("Vin2", "Hvidvin", 5000, "Le Pas Deux", "Spanien", 1982, "Gode2", 3.25, "500 cl", 1)));
	pro.add(new Auction(5500, d.format(new Date(1392465600)), "Someone12", new Wine("Vin3", "Rosevin", 7500, "Le Pas Tri", "Rusland", 1889, "Gode3", 50.00, "1750 cl", 2)));
    }
    private void loadUser(){
	use.add(new User("Bruger1", "1234", "Vejgade 3",12345678));
	use.add(new User("Bruger2", "1234", "Vejgade 2",89652345));
	use.add(new User("Bruger3", "1234", "Vejgade 1",48563245));
    }
    private void loadBid(){
	bid.add(new Bid(pro.get(0), use.get(1), 2500));
	bid.add(new Bid(pro.get(0), use.get(0), 3210));
	bid.add(new Bid(pro.get(1), use.get(2), 500));
	bid.add(new Bid(pro.get(2), use.get(0), 5000));
	bid.add(new Bid(pro.get(3), use.get(1), 200));
	bid.add(new Bid(pro.get(4), use.get(0), 3500));
	bid.add(new Bid(pro.get(4), use.get(2), 4500));
	bid.add(new Bid(pro.get(4), use.get(0), 5000));
	bid.add(new Bid(pro.get(5), use.get(0), 8500));
	bid.add(new Bid(pro.get(6), use.get(1), 5500));
	bid.add(new Bid(pro.get(7), use.get(2), 6500));
	bid.add(new Bid(pro.get(7), use.get(1), 8500));
	bid.add(new Bid(pro.get(7), use.get(0), 10000));
	bid.add(new Bid(pro.get(8), use.get(0), 3500));
	bid.add(new Bid(pro.get(9), use.get(0), 1500));
	bid.add(new Bid(pro.get(9), use.get(2), 2000));
	bid.add(new Bid(pro.get(10), use.get(1), 1000));
	bid.add(new Bid(pro.get(10), use.get(0), 1200));
	bid.add(new Bid(pro.get(10), use.get(1), 1800));
	bid.add(new Bid(pro.get(11), use.get(0), 5500));
    }
}
